#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
using namespace std;







struct item{
	int value,weight;
};


struct jia{
	int a,b;
	int cac(int x){
		return a*x*x-b*x;
	}
};


int main(){
	int ans=0;
	vector<item> v;
	vector<jia> v2;
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		int k;
		cin>>k;
		if(k == 1){
			int a,b;
			cin>>a>>b;
			jia w;
			w.a = a;
			w.b = b;
			v2.push_back(w);
		}
		else if(k == 2){
			int a,b,c;
			cin>>a>>b>>c;
			c = (min(c*b,m))/b;
			int d=1;
			while(2*d < c){
				item l;
				l.weight = d*b;
				l.value = d*a;
				v.push_back(l);
				d *= 2;
			}
			d = c-(d-1);
			if(d == 0)
				continue;
			item l;
			l.weight = d*b;
			l.value = d*a;
			v.push_back(l);
		}
		else{
			int a,b;
			cin>>a>>b;
			int c=1;
			while((2*c)*b < m){
				item l;
				l.weight = c*b;
				l.value = c*a;
				v.push_back(l);
				c *= 2;
			}
			c = (m/b-(c-1));
			if(c == 0)
				continue;
			item l;
			l.weight = c*b;
			l.value = c*a;
			v.push_back(l);
		}
	}
	
	
	n = v.size();
	int dp[n+1][m+1];
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			dp[i][j] = ((j-v[i-1].weight)>=0)?max(dp[i-1][j],dp[i-1][j-v[i-1].weight]+v[i-1].value):dp[i-1][j];
		}
	}
	ans = max(ans,dp[n][m]);
	for(int i=0;i<v2.size();i++){
		for(int j=m;j>=0;j--){
			for(int k=0;k<=j;k++){
//				cout<<i<<" "<<j<<endl;
				dp[n][j] = max(dp[n][j],dp[n][j-k]+v2[i].cac(k));
//				cout<<i<<" "<<j<<endl;
				ans = max(ans,dp[n][j]);
			}
		}
	}
//	for(int i=0;i<n;i++){
//		cout<<v[i].weight<<" "<<v[i].value<<endl;
//	}
//	for(int i=0;i<=n;i++){
//		for(int j=0;j<=m;j++)
//			cout<<dp[i][j]<<" ";
//		cout<<endl;
//	}
	cout<<ans;
	return 0;
}
